# -*- coding: utf-8 -*-
import scrapy
# from scrapy.http import Request
# from urllib import parse
# scrapy crawl caipiao -o qxc.json -s FEED_EXPORT_ENCODING=utf-8

class CaipiaoSpider(scrapy.Spider):
    name = 'caipiao'
    allowed_domains = ['caipiao.com']
    start_urls = ['http://kaijiang.500.com/qxc.shtml']
    # http: // kaijiang.500.com / shtml / qxc / 04101.shtml
    stage = 4101
    while stage < 18011:
        stage_num = str(stage)
        stage_str = stage_num.zfill(5)
        next_url = 'http://kaijiang.500.com/shtml/qxc/'+stage_str+'.shtml'
        start_urls.append(next_url)
        stage = stage+1

    def parse(self, response):
        num01 = response.css('.ball_orange:nth-child(1)::text').extract_first()
        num02 = response.css('.ball_orange:nth-child(2)::text').extract_first()
        num03 = response.css('.ball_orange:nth-child(3)::text').extract_first()
        num04 = response.css('.ball_orange:nth-child(4)::text').extract_first()
        num05 = response.css('.ball_orange:nth-child(5)::text').extract_first()
        num06 = response.css('.ball_orange:nth-child(6)::text').extract_first()
        num07 = response.css('.ball_orange:nth-child(7)::text').extract_first()
        yield {
            'num01':num01,
            'num02': num02,
            'num03': num03,
            'num04': num04,
            'num05': num05,
            'num06': num06,
            'num07': num07
        }
        pass
